package com.file.transfers;

import java.net.URL;

import com.file.transfers.socket.FileTransfersClient;
import com.file.transfers.socket.FileTransfersServer;
import com.file.transfers.util.ResourceProperties;

public class Main {
	private static final String P_FILE = "ft_runtime.properties";
	public static ResourceProperties properties;
	public static FileTransfersClient fileTransfersClient;
	public static FileTransfersServer fileTransfersServer;
	static{
		properties=new ResourceProperties("./"+P_FILE);
		System.out.println("读取资源文件成功");
	}
	public static void startServer(int p,String f) {
		
		if(p==0){
			p=Main.properties.getInt("port");
		}
		if(f!=null || "".equals(f)){
			f=Main.properties.getString("filePath");
		}
		fileTransfersServer=new FileTransfersServer(p,f);
		fileTransfersServer.start();
	}
	public static void startClient(String ip,int port){
		fileTransfersClient=new FileTransfersClient(ip,port);
	}
	public static void main(String[] args) {
		//String replace = Main.class.getName().replace(".", "/");
		//System.out.println(replace);
		String resource = Main.class.getResource("/").toString();
		resource=resource.substring(0, resource.length()-1);
		int lastIndexOf = resource.lastIndexOf("//");
		System.out.println(lastIndexOf);
		String substring = resource.substring(0, 1);
		System.out.println(resource);
		properties=new ResourceProperties(P_FILE);
		int p=Main.properties.getInt("port");
		System.out.println(p);
	}
}
